---
title: "Replication file (II)"
output: html_document
date: "2025-01-10"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(tidyverse)
library(rms)
library(stargazer)
library(multcomp)
library(margins)
library(kableExtra)
library(MASS)
```

# Download data

```{r}
data_wave2 <- read_csv("data_wave2.csv")
```

# Reorder factors

```{r}
data_wave2 <- data_wave2 %>%  
  mutate(immi_background_rec = factor(immi_background_rec, levels = c("Other/Native", "Immigrant", "Child of immigrants"))) %>% 
  mutate(nationality = factor(nationality, levels = c("Only survey country nationality", "Survey country and other nationality", "Only other nationality"))) %>% 
  mutate(country_origin = factor(country_origin, levels = c("Survey country", "Europe and North America", "Asia", "Latin America and Caribbean", "Africa and Middle East"))) %>% 
  mutate(immi_background_dic = factor(immi_background_dic, levels = c("Native", "Immigrant"))) %>% 
  mutate(combi_fem_migr = factor(combi_fem_migr, levels = c("Native_Male", "Native_Female", "Immigrant_Male", "Child_of_Immigrants_Male", "Immigrant_Female", "Child_of_Immigrants_Female")))
```


# Descriptives table

```{r}
descriptives_total <- data_wave2 %>%
  group_by(country) %>%
  summarise(
    "Female" = round(mean(female == 1, na.rm = TRUE) * 100, 2),
    "Male" = round(mean(female == 0, na.rm = TRUE) * 100, 2),
    "Native" = round(mean(immi_background_rec == "Other/Native", na.rm = TRUE) * 100, 2),
    "Immigrant" = round(mean(immi_background_rec == "Immigrant", na.rm = TRUE) * 100, 2),
    "Child of immigrants" = round(mean(immi_background_rec == "Child of immigrants", na.rm = TRUE) * 100, 2),
    "Africa and Middle East" = round(mean(country_origin == "Africa and Middle East", na.rm = TRUE) * 100, 2),
    "Asia" = round(mean(country_origin == "Asia", na.rm = TRUE) * 100, 2),
    "Latin America and Caribbean" = round(mean(country_origin == "Latin America and Caribbean", na.rm = TRUE) * 100, 2),
    "Europe and North America" = round(mean(country_origin == "Europe and North America", na.rm = TRUE) * 100, 2),
    "Survey country" = round(mean(country_origin == "Survey country", na.rm = TRUE) * 100, 2),
    "Only survey country nationality" = round(mean(nationality == "Only survey country nationality", na.rm = TRUE) * 100, 2),
    "Only other nationality" = round(mean(nationality == "Only other nationality", na.rm = TRUE) * 100, 2),
    "Survey country and other nationality" = round(mean(nationality == "Survey country and other nationality", na.rm = TRUE) * 100, 2),
    "Age" = round(mean(age, na.rm = TRUE), 2),
    "Parents political talk" = round(mean(talk_parents_pol, na.rm = TRUE), 2),
    "Associationism" = round(mean(associationism, na.rm = TRUE), 2),
    "Religious participation" = round(mean(religious_part, na.rm = TRUE), 2),
    "Half or more of friends other group" = round(mean(mixed_friend == 1, na.rm = TRUE) * 100, 2),
    "Half or more of friends same group" = round(mean(mixed_friend == 0, na.rm = TRUE) * 100, 2),
    "N" = n()  ) %>%
  pivot_longer(cols = -country, names_to = "Variables", values_to = "value") %>%
  pivot_wider(names_from = country, values_from = value)


country_names <- c("England", "Germany", "Netherlands", "Sweden")
sections <- tibble(
  Variables = c("Gender", "Immigrant background", "Country origin", "Nationality", "Mixed friendship"))

for (country in country_names) {
  sections[[country]] <- rep("", nrow(sections))}


table_final <- descriptives_total %>% 
  rbind(sections)

table_final <- table_final %>%
  mutate(Variables = factor(Variables, levels = c(
    "Gender", "Female", "Male", 
    "Immigrant background", "Native", "Immigrant", "Child of immigrants", 
    "Country origin", "Africa and Middle East", "Asia", "Latin America and Caribbean", "Europe and North America", "Survey country", 
    "Nationality", "Only survey country nationality", "Only other nationality", "Survey country and other nationality", 
    "Age", "Parents political talk", "Associationism", "Religious participation", 
    "Mixed friendship", "Half or more of friends other group", "Half or more of friends same group", "N"))) %>%
  arrange(Variables)
```

```{r}
kable(table_final, format = "html", caption = "<b>Table 1. Descriptive statistics wave 2</b>") %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("hover", "condensed")) %>% 
  column_spec(1, border_right = TRUE) %>% 
  row_spec(1, bold = TRUE) %>%
  row_spec(4, bold = TRUE) %>%
  row_spec(8, bold = TRUE) %>%
  row_spec(14, bold = TRUE) %>%
  row_spec(18, bold = TRUE) %>%
  row_spec(19, bold = TRUE) %>%
  row_spec(20, bold = TRUE) %>%
  row_spec(21, bold = TRUE) %>%
  row_spec(22, bold = TRUE) %>%
  row_spec(25, bold = TRUE) %>%
  row_spec(0, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(3, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(7, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(13, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(17, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(18, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(19, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(20, extra_css = "border-bottom: 1px solid black;") %>%
  row_spec(21, extra_css = "border-bottom: 1px solid black;") %>% 
  row_spec(24, extra_css = "border-bottom: 1px solid black;") 
```

# Hypothesis 1

## Models hypothesis 1

### Data for the models

```{r}
data_model_h1 <- data_wave2 %>% 
  dplyr::select(poliint, female, immi_background_dic, country_origin, nationality, age, book_home, talk_parents_pol, associationism, religious_part, mixed_friend, combi_fem_migr) %>% 
  na.omit()
```

### The models

```{r}
h1_model1 <- lm(poliint ~ female + immi_background_dic, data = data_model_h1)
summary(h1_model1)
```

```{r}
h1_model2 <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic, data = data_model_h1)
summary(h1_model2)
```

```{r}
h1_model3 <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_model_h1)
summary(h1_model3)
```

## Interpretation of the interactions

```{r}
h1_compar2 <- glht(h1_model2, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_compar2)
```

## Coefficient plot

```{r}
coef_h1_model2 <- coef(h1_model2)
confint_h1_model2 <- confint(h1_model2)

table_h1_model2 <- data.frame(
  category = names(coef_h1_model2),
  coefficient = coef_h1_model2,
  IC_Lower = confint_h1_model2[, 1],
  IC_Upper = confint_h1_model2[, 2])
```

```{r}
coef_h1_compar2 <- summary(h1_compar2)$test$coefficients
confint_h1_compar2 <- confint(h1_compar2)$confint

table_h1_compar2 <- data.frame(
  category = names(coef_h1_compar2),
  coefficient = coef_h1_compar2,
  IC_Lower = confint_h1_compar2[, 2],
  IC_Upper = confint_h1_compar2[, 3])
```

```{r}
plot_h1_model2 <- table_h1_model2 %>% 
  rbind(table_h1_compar2) %>% 
  filter(category %in% c("female", "immi_background_dicImmigrant", "female + `female:immi_background_dicImmigrant`", "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`", "female:immi_background_dicImmigrant")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_dicImmigrant" ~ "Interaction effect for girl and immigrant background",
    category == "female" ~ "Differences of being girl among non-immigrant background",
    category == "immi_background_dicImmigrant" ~ "Differences of immigrant background among boys",
    category == "female + `female:immi_background_dicImmigrant`" ~ "Differences of being girl among immigrant background",
    category == "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`" ~ "Differences of immigrant background among girls")) %>% 
  mutate(category = factor(category, levels = c("Differences of immigrant background among boys", 
                                                "Differences of immigrant background among girls",
                                                "Differences of being girl among immigrant background", 
                                                "Differences of being girl among non-immigrant background", 
                                                "Interaction effect for girl and immigrant background")))
```

```{r}
h1_NO_CONTROL <- ggplot(plot_h1_model2, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.75) + 
  theme_minimal() +
  theme(panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0,size = 9,face = "bold",margin = margin(t = 20)))
plot(h1_NO_CONTROL)
```

### Model 3 with controls

```{r}
h1_compar3 <- glht(h1_model3, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_compar3)
```

## Coefficient plot

```{r}
coef_h1_model3 <- coef(h1_model3)
confint_h1_model3 <- confint(h1_model3)

table_h1_model3 <- data.frame(
  category = names(coef_h1_model3),
  coefficient = coef_h1_model3,
  IC_Lower = confint_h1_model3[, 1],
  IC_Upper = confint_h1_model3[, 2])
```

```{r}
coef_h1_compar3 <- summary(h1_compar3)$test$coefficients
confint_h1_compar3 <- confint(h1_compar3)$confint

table_h1_compar3 <- data.frame(
  category = names(coef_h1_compar3),
  coefficient = coef_h1_compar3,
  IC_Lower = confint_h1_compar3[, 2],
  IC_Upper = confint_h1_compar3[, 3])
```

```{r}
plot_h1_model3 <- table_h1_model3 %>% 
  rbind(table_h1_compar3) %>% 
  filter(category %in% c("female", "immi_background_dicImmigrant", "female + `female:immi_background_dicImmigrant`", "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`", "female:immi_background_dicImmigrant")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_dicImmigrant" ~ "Interaction effect for girl and immigrant background",
    category == "female" ~ "Differences of being girl among non-immigrant background",
    category == "immi_background_dicImmigrant" ~ "Differences of immigrant background among boys",
    category == "female + `female:immi_background_dicImmigrant`" ~ "Differences of being girl among immigrant background",
    category == "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`" ~ "Differences of immigrant background among girls")) %>% 
  mutate(category = factor(category, levels = c("Differences of immigrant background among boys", 
                                                "Differences of immigrant background among girls",
                                                "Differences of being girl among immigrant background", 
                                                "Differences of being girl among non-immigrant background", 
                                                "Interaction effect for girl and immigrant background")))
```

```{r}
h1_WITH_CONTROL <- ggplot(plot_h1_model3, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.75) + 
  theme_minimal() +
  theme(panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0,size = 9,face = "bold",margin = margin(t = 20))) 
plot(h1_WITH_CONTROL)
```


## Models FOR COUNTRIES

### Filter for each country

```{r}
data_wave2_en <- data_wave2 %>%
  filter(country == "England") %>% 
  dplyr::select(poliint, female, immi_background_dic, immi_background_rec, combi_fem_migr, country_origin, nationality, age, book_home, talk_parents_pol, associationism, religious_part, mixed_friend) %>% 
  na.omit()

data_wave2_ger <- data_wave2 %>%
  filter(country == "Germany") %>% 
  dplyr::select(poliint, female, immi_background_dic, immi_background_rec, combi_fem_migr, country_origin, nationality, age, book_home, talk_parents_pol, associationism, religious_part, mixed_friend) %>% 
  na.omit()

data_wave2_neth <- data_wave2 %>%
  filter(country == "Netherlands") %>% 
  dplyr::select(poliint, female, immi_background_dic, immi_background_rec, combi_fem_migr, country_origin, nationality, age, book_home, talk_parents_pol, associationism, religious_part, mixed_friend) %>% 
  na.omit()

data_wave2_sw <- data_wave2 %>%
  filter(country == "Sweden") %>% 
  dplyr::select(poliint, female, immi_background_dic, immi_background_rec, combi_fem_migr, country_origin, nationality, age, book_home, talk_parents_pol, associationism, religious_part, mixed_friend) %>% 
  na.omit()
```

### Hypothesis 1

#### WITHOUT controls

```{r}
h1_en_nocon <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic, data = data_wave2_en)
summary(h1_en_nocon)
```

```{r}
h1_ger_nocon <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic, data = data_wave2_ger)
summary(h1_ger_nocon)
```

```{r}
h1_neth_nocon <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic , data = data_wave2_neth)
summary(h1_neth_nocon)
```

```{r}
h1_sw_nocon <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic, data = data_wave2_sw)
summary(h1_sw_nocon)
```

#### WITH controls

```{r}
h1_model3_en <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_en)
summary(h1_model3_en)
```

```{r}
h1_model3_ger <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_ger)
summary(h1_model3_ger)
```

```{r}
h1_model3_neth <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_neth)
summary(h1_model3_neth)
```

```{r}
h1_model3_sw <- lm(poliint ~ female + immi_background_dic + female*immi_background_dic + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_sw)
summary(h1_model3_sw)
```

## Calculo los coeficientes

### Without controls

```{r}
h1_en_nocon_comp <- glht(h1_en_nocon, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_en_nocon_comp)
```

```{r}
h1_ger_nocon_comp <- glht(h1_ger_nocon, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_ger_nocon_comp)
```

```{r}
h1_neth_nocon_comp <- glht(h1_neth_nocon, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_neth_nocon_comp)
```

```{r}
h1_sw_nocon_comp <- glht(h1_sw_nocon, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_sw_nocon_comp)
```

### With controls

```{r}
h1_en_con_comp <- glht(h1_model3_en, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_en_con_comp)
```

```{r}
h1_ger_con_comp <- glht(h1_model3_ger, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_ger_con_comp)
```

```{r}
h1_neth_con_comp <- glht(h1_model3_neth, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_neth_con_comp)
```

```{r}
h1_sw_con_comp <- glht(h1_model3_sw, 
                    linfct = c("female + `female:immi_background_dicImmigrant` = 0",
                               "`immi_background_dicImmigrant` + `female:immi_background_dicImmigrant` = 0"))

summary(h1_sw_con_comp)
```

# Coefficient plot

### Without controls

### England

```{r}
coef_h1_en_nocon <- coef(h1_en_nocon)
confint_h1_en_nocon <- confint(h1_en_nocon)

table_h1_en_nocon <- data.frame(
  category = names(coef_h1_en_nocon),
  coefficient = coef_h1_en_nocon,
  IC_Lower = confint_h1_en_nocon[, 1],
  IC_Upper = confint_h1_en_nocon[, 2]) %>% 
  mutate(country = "England")
```

```{r}
coef_h1_en_nocon_comp <- summary(h1_en_nocon_comp)$test$coefficients
confint_h1_en_nocon_comp <- confint(h1_en_nocon_comp)$confint

table_h1_en_nocon_comp <- data.frame(
  category = names(coef_h1_en_nocon_comp),
  coefficient = coef_h1_en_nocon_comp,
  IC_Lower = confint_h1_en_nocon_comp[, 2],
  IC_Upper = confint_h1_en_nocon_comp[, 3]) %>% 
  mutate(country = "England")
```

### Germany

```{r}
coef_h1_ger_nocon <- coef(h1_ger_nocon)
confint_h1_ger_nocon <- confint(h1_ger_nocon)

table_h1_ger_nocon <- data.frame(
  category = names(coef_h1_ger_nocon),
  coefficient = coef_h1_ger_nocon,
  IC_Lower = confint_h1_ger_nocon[, 1],
  IC_Upper = confint_h1_ger_nocon[, 2])%>% 
  mutate(country = "Germany")
```

```{r}
coef_h1_ger_nocon_comp <- summary(h1_ger_nocon_comp)$test$coefficients
confint_h1_ger_nocon_comp <- confint(h1_ger_nocon_comp)$confint

table_h1_ger_nocon_comp <- data.frame(
  category = names(coef_h1_ger_nocon_comp),
  coefficient = coef_h1_ger_nocon_comp,
  IC_Lower = confint_h1_ger_nocon_comp[, 2],
  IC_Upper = confint_h1_ger_nocon_comp[, 3])%>% 
  mutate(country = "Germany")
```

### Netherlands

```{r}
coef_h1_neth_nocon <- coef(h1_neth_nocon)
confint_h1_neth_nocon <- confint(h1_neth_nocon)

table_h1_neth_nocon <- data.frame(
  category = names(coef_h1_neth_nocon),
  coefficient = coef_h1_neth_nocon,
  IC_Lower = confint_h1_neth_nocon[, 1],
  IC_Upper = confint_h1_neth_nocon[, 2]) %>% 
  mutate(country = "Netherlands")
```

```{r}
coef_h1_neth_nocon_comp <- summary(h1_neth_nocon_comp)$test$coefficients
confint_h1_neth_nocon_comp <- confint(h1_neth_nocon_comp)$confint

table_h1_neth_nocon_comp <- data.frame(
  category = names(coef_h1_neth_nocon_comp),
  coefficient = coef_h1_neth_nocon_comp,
  IC_Lower = confint_h1_neth_nocon_comp[, 2],
  IC_Upper = confint_h1_neth_nocon_comp[, 3]) %>% 
  mutate(country = "Netherlands")
```

### Sweden

```{r}
coef_h1_sw_nocon <- coef(h1_sw_nocon)
confint_h1_sw_nocon <- confint(h1_sw_nocon)

table_h1_sw_nocon <- data.frame(
  category = names(coef_h1_sw_nocon),
  coefficient = coef_h1_sw_nocon,
  IC_Lower = confint_h1_sw_nocon[, 1],
  IC_Upper = confint_h1_sw_nocon[, 2]) %>% 
  mutate(country = "Sweden")
```

```{r}
coef_h1_sw_nocon_comp <- summary(h1_sw_nocon_comp)$test$coefficients
confint_h1_sw_nocon_comp <- confint(h1_sw_nocon_comp)$confint

table_h1_sw_nocon_comp <- data.frame(
  category = names(coef_h1_sw_nocon_comp),
  coefficient = coef_h1_sw_nocon_comp,
  IC_Lower = confint_h1_sw_nocon_comp[, 2],
  IC_Upper = confint_h1_sw_nocon_comp[, 3]) %>% 
  mutate(country = "Sweden")
```

## Plot 

```{r}
plot_h1_nocon_coun <- table_h1_en_nocon %>% 
  rbind(table_h1_en_nocon_comp) %>% 
  rbind(table_h1_ger_nocon) %>% 
  rbind(table_h1_ger_nocon_comp) %>% 
  rbind(table_h1_neth_nocon) %>% 
  rbind(table_h1_neth_nocon_comp) %>% 
  rbind(table_h1_sw_nocon) %>% 
  rbind(table_h1_sw_nocon_comp) %>% 
  filter(category %in% c("female", "immi_background_dicImmigrant", "female + `female:immi_background_dicImmigrant`", "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`", "female:immi_background_dicImmigrant")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_dicImmigrant" ~ "Interaction effect for girl and immigrant background",
    category == "female" ~ "Differences of being girl among non-immigrant background",
    category == "immi_background_dicImmigrant" ~ "Differences of immigrant background among boys",
    category == "female + `female:immi_background_dicImmigrant`" ~ "Differences of being girl among immigrant background",
    category == "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`" ~ "Differences of immigrant background among girls")) %>% 
  mutate(category = factor(category, levels = c("Differences of immigrant background among boys", 
                                                "Differences of immigrant background among girls",
                                                "Differences of being girl among immigrant background", 
                                                "Differences of being girl among non-immigrant background", 
                                                "Interaction effect for girl and immigrant background")))
```

```{r, fig.width=10, fig.height=7}
h1_nocon_count <- ggplot(plot_h1_nocon_coun, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.75) + 
  facet_wrap(~ country, ncol = 2) +
  theme_minimal() +
  scale_y_discrete(labels = function(x) str_wrap(x, width = 60)) +  
  theme(panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0,size = 9,face = "bold",margin = margin(t = 20))) 
plot(h1_nocon_count)
```


### With controls

### England

```{r}
coef_h1_model3_en <- coef(h1_model3_en)
confint_h1_model3_en <- confint(h1_model3_en)

table_h1_model3_en <- data.frame(
  category = names(coef_h1_model3_en),
  coefficient = coef_h1_model3_en,
  IC_Lower = confint_h1_model3_en[, 1],
  IC_Upper = confint_h1_model3_en[, 2]) %>% 
  mutate(country = "England")
```

```{r}
coef_h1_en_con_comp <- summary(h1_en_con_comp)$test$coefficients
confint_h1_en_con_comp <- confint(h1_en_con_comp)$confint

table_h1_en_con_comp <- data.frame(
  category = names(coef_h1_en_con_comp),
  coefficient = coef_h1_en_con_comp,
  IC_Lower = confint_h1_en_con_comp[, 2],
  IC_Upper = confint_h1_en_con_comp[, 3]) %>% 
  mutate(country = "England")
```

### Germany

```{r}
coef_h1_model3_ger <- coef(h1_model3_ger)
confint_h1_model3_ger <- confint(h1_model3_ger)

table_h1_model3_ger <- data.frame(
  category = names(coef_h1_model3_ger),
  coefficient = coef_h1_model3_ger,
  IC_Lower = confint_h1_model3_ger[, 1],
  IC_Upper = confint_h1_model3_ger[, 2]) %>% 
  mutate(country = "Germany")
```

```{r}
coef_h1_ger_con_comp <- summary(h1_ger_con_comp)$test$coefficients
confint_h1_ger_con_comp <- confint(h1_ger_con_comp)$confint

table_h1_ger_con_comp <- data.frame(
  category = names(coef_h1_ger_con_comp),
  coefficient = coef_h1_ger_con_comp,
  IC_Lower = confint_h1_ger_con_comp[, 2],
  IC_Upper = confint_h1_ger_con_comp[, 3]) %>% 
  mutate(country = "Germany")
```

### Netherlands

```{r}
coef_h1_model3_neth <- coef(h1_model3_neth)
confint_h1_model3_neth <- confint(h1_model3_neth)

table_h1_model3_neth <- data.frame(
  category = names(coef_h1_model3_neth),
  coefficient = coef_h1_model3_neth,
  IC_Lower = confint_h1_model3_neth[, 1],
  IC_Upper = confint_h1_model3_neth[, 2]) %>% 
  mutate(country = "Netherlands")
```

```{r}
coef_h1_neth_con_comp <- summary(h1_neth_con_comp)$test$coefficients
confint_h1_neth_con_comp <- confint(h1_neth_con_comp)$confint

table_h1_neth_con_comp <- data.frame(
  category = names(coef_h1_neth_con_comp),
  coefficient = coef_h1_neth_con_comp,
  IC_Lower = confint_h1_neth_con_comp[, 2],
  IC_Upper = confint_h1_neth_con_comp[, 3]) %>% 
  mutate(country = "Netherlands")
```

### Sweden

```{r}
coef_h1_model3_sw <- coef(h1_model3_sw)
confint_h1_model3_sw <- confint(h1_model3_sw)

table_h1_model3_sw <- data.frame(
  category = names(coef_h1_model3_sw),
  coefficient = coef_h1_model3_sw,
  IC_Lower = confint_h1_model3_sw[, 1],
  IC_Upper = confint_h1_model3_sw[, 2]) %>% 
  mutate(country = "Sweden")
```

```{r}
coef_h1_sw_con_comp <- summary(h1_sw_con_comp)$test$coefficients
confint_h1_sw_con_comp <- confint(h1_sw_con_comp)$confint

table_h1_sw_con_comp <- data.frame(
  category = names(coef_h1_sw_con_comp),
  coefficient = coef_h1_sw_con_comp,
  IC_Lower = confint_h1_sw_con_comp[, 2],
  IC_Upper = confint_h1_sw_con_comp[, 3]) %>% 
  mutate(country = "Sweden")
```

## Plot 

```{r}
plot_h1_con_coun <- table_h1_model3_en %>% 
  rbind(table_h1_en_con_comp) %>% 
  rbind(table_h1_model3_ger) %>% 
  rbind(table_h1_ger_con_comp) %>% 
  rbind(table_h1_model3_neth) %>% 
  rbind(table_h1_neth_con_comp) %>% 
  rbind(table_h1_model3_sw) %>% 
  rbind(table_h1_sw_con_comp) %>% 
  filter(category %in% c("female", "immi_background_dicImmigrant", "female + `female:immi_background_dicImmigrant`", "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`", "female:immi_background_dicImmigrant")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_dicImmigrant" ~ "Interaction effect for girl and immigrant background",
    category == "female" ~ "Differences of being girl among non-immigrant background",
    category == "immi_background_dicImmigrant" ~ "Differences of immigrant background among boys",
    category == "female + `female:immi_background_dicImmigrant`" ~ "Differences of being girl among immigrant background",
    category == "immi_background_dicImmigrant + `female:immi_background_dicImmigrant`" ~ "Differences of immigrant background among girls")) %>% 
  mutate(category = factor(category, levels = c("Differences of immigrant background among boys", 
                                                "Differences of immigrant background among girls",
                                                "Differences of being girl among immigrant background", 
                                                "Differences of being girl among non-immigrant background", 
                                                "Interaction effect for girl and immigrant background")))
```

```{r, fig.width=10, fig.height=7}
h1_con_count <- ggplot(plot_h1_con_coun, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.75) + 
  facet_wrap(~ country, ncol = 2) +
  theme_minimal() +
  scale_y_discrete(labels = function(x) str_wrap(x, width = 60)) +  
  theme(panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0,size = 9,face = "bold",margin = margin(t = 20)))  
plot(h1_con_count)
```


# Hypothesis 2

## Select data

```{r}
data_model_h2 <- data_wave2 %>% 
  dplyr::select(poliint, female, immi_background_rec, country_origin, nationality, age, book_home, talk_parents_pol, associationism, religious_part, mixed_friend, combi_fem_migr) %>%
  na.omit()
```

## Models

```{r}
w2_model1 <- lm(poliint ~ female + immi_background_rec, data = data_model_h2)
summary(w2_model1)
```

```{r}
w2_model2 <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec, data = data_model_h2)
summary(w2_model2)
```

```{r}
w2_model3 <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_model_h2)
summary(w2_model3)
```

## Interactions

```{r}
comparisons <- glht(w2_model2, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))

summary(comparisons)
```

## Coefficient plot

```{r}
coef_model <- coef(w2_model2)
confint_model <- confint(w2_model2)

table_model <- data.frame(
  category = names(coef_model),
  coefficient = coef_model,
  IC_Lower = confint_model[, 1],
  IC_Upper = confint_model[, 2])
```

```{r}
coef_comp <- summary(comparisons)$test$coefficients
confint_comp <- confint(comparisons)$confint

table_comparisons <- data.frame(
  category = names(coef_comp),
  coefficient = coef_comp,
  IC_Lower = confint_comp[, 2],
  IC_Upper = confint_comp[, 3])
```

## Coefficient Child of Immigrant women vs Immigrant women

### Regression

```{r}
w2_model3_alter<- lm(poliint ~ combi_fem_migr, data = data_model_h2)
summary(w2_model3_alter)
```

### Compare 

```{r}
compa_alter <- glht(w2_model3_alter, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
compa_alter_res <- summary(compa_alter)
```

## Coefficient plot

```{r}
coef_child_vs_immigrant <- coef(compa_alter_res)
confint_child_vs_immigrant <- confint(compa_alter)$confint

table_compa_alter <- data.frame(
  category = names(coef_child_vs_immigrant),
  coefficient = coef_child_vs_immigrant,
  IC_Lower = confint_child_vs_immigrant[, 2],
  IC_Upper = confint_child_vs_immigrant[, 3])
```

#### Table

```{r}
plot_def <- table_model %>%
  rbind(table_comparisons) %>% 
  rbind(table_compa_alter) %>% 
  filter(category %in% c("female", "immi_background_recImmigrant", "immi_background_recChild of immigrants", "female:immi_background_recImmigrant", "female:immi_background_recChild of immigrants", "female + `female:immi_background_recImmigrant`", "female + `female:immi_background_recChild of immigrants`", "immi_background_recImmigrant + `female:immi_background_recImmigrant`", "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`", "Child_of_Immigrants_Female - Immigrant_Female")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_recImmigrant" ~ "Interaction effect for female and immigrant background",
    category == "female:immi_background_recChild of immigrants" ~ "Interaction effect for female and adolescents with foreign-born parents", 
    category == "female" ~ "Differences of being female among non-immigrant background", 
    category == "immi_background_recImmigrant" ~ "Differences of immigrant background among males",
    category == "immi_background_recChild of immigrants" ~ "Differences of being an adolescents with foreign-born parents among males",
    category == "female + `female:immi_background_recImmigrant`" ~ "Differences of being female among immigrant background", 
    category == "female + `female:immi_background_recChild of immigrants`" ~ "Differences of being female among adolescents with foreign-born parents", 
    category == "immi_background_recImmigrant + `female:immi_background_recImmigrant`" ~ "Differences of immigrant background among females",
    category == "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`" ~ "Differences of being an adolescents with foreign-born parents among females",
      category == "Child_of_Immigrants_Female - Immigrant_Female" ~ "Differences of being a female adolescent with foreign-born parents vs immigrant background female")) %>% 
  mutate(category = factor(category, levels = c("Differences of being a female adolescent with foreign-born parents vs immigrant background female",
                                                "Differences of being an adolescents with foreign-born parents among males",
                                                "Differences of being an adolescents with foreign-born parents among females",
                                                "Differences of immigrant background among males",
                                                "Differences of immigrant background among females",
                                                "Differences of being female among adolescents with foreign-born parents", 
                                                "Differences of being female among immigrant background", 
                                                "Differences of being female among non-immigrant background", 
                                                "Interaction effect for female and adolescents with foreign-born parents", 
                                                "Interaction effect for female and immigrant background")))
```

```{r}
h2_plot <- ggplot(plot_def, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.75) + 
  theme_minimal() +
  scale_y_discrete(labels = function(x) str_wrap(x, width = 51)) +  
  theme(panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0,size = 9,face = "bold",margin = margin(t = 20)),
    axis.text.y = element_text(size = 9)) 
plot(h2_plot)
```


## Hypothesis 2 with controls


```{r}
comparisons_con <- glht(w2_model3, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))

summary(comparisons_con)
```

## Coefficient plot

```{r}
coef_model_con <- coef(w2_model3)
confint_model_con <- confint(w2_model3)

table_model_con <- data.frame(
  category = names(coef_model_con),
  coefficient = coef_model_con,
  IC_Lower = confint_model_con[, 1],
  IC_Upper = confint_model_con[, 2])
```

```{r}
coef_comp_con <- summary(comparisons_con)$test$coefficients
confint_comp_con <- confint(comparisons_con)$confint

table_comparisons_con <- data.frame(
  category = names(coef_comp_con),
  coefficient = coef_comp_con,
  IC_Lower = confint_comp_con[, 2],
  IC_Upper = confint_comp_con[, 3])
```

### Alternative regression 

```{r}
w2_model3_alter_con <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_model_h2)
summary(w2_model3_alter_con)
```

```{r}
compa_alter_con <- glht(w2_model3_alter_con, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
compa_alter_res_con <- summary(compa_alter_con)
```

## Coefficient plot

```{r}
coef_child_vs_immigrant_con <- coef(compa_alter_res_con)
confint_child_vs_immigrant_con <- confint(compa_alter_con)$confint

table_compa_alter_con <- data.frame(
  category = names(coef_child_vs_immigrant_con),
  coefficient = coef_child_vs_immigrant_con,
  IC_Lower = confint_child_vs_immigrant_con[, 2],
  IC_Upper = confint_child_vs_immigrant_con[, 3])
```

#### Table

```{r}
plot_def_con <- table_model_con %>%
  rbind(table_comparisons_con) %>% 
  rbind(table_compa_alter_con) %>% 
  filter(category %in% c("female", "immi_background_recImmigrant", "immi_background_recChild of immigrants", "female:immi_background_recImmigrant", "female:immi_background_recChild of immigrants", "female + `female:immi_background_recImmigrant`", "female + `female:immi_background_recChild of immigrants`", "immi_background_recImmigrant + `female:immi_background_recImmigrant`", "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`", "Child_of_Immigrants_Female - Immigrant_Female")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_recImmigrant" ~ "Interaction effect for girl and immigrant background",
    category == "female:immi_background_recChild of immigrants" ~ "Interaction effect for girl and adolescents with foreign-born parents",
    category == "female" ~ "Differences of being girl among non-immigrant background",
    category == "immi_background_recImmigrant" ~ "Differences of immigrant background among boys",
    category == "immi_background_recChild of immigrants" ~ "Differences of being an adolescents with foreign-born parents among boys",
    category == "female + `female:immi_background_recImmigrant`" ~ "Differences of being girl among immigrant background",
    category == "female + `female:immi_background_recChild of immigrants`" ~ "Differences of being girl among adolescents with foreign-born parents", 
    category == "immi_background_recImmigrant + `female:immi_background_recImmigrant`" ~ "Differences of immigrant background among girls",
    category == "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`" ~ "Differences of being an adolescents with foreign-born parents among girls",
      category == "Child_of_Immigrants_Female - Immigrant_Female" ~ "Differences of being a girl adolescent with foreign-born parents vs immigrant background girl")) %>% 
  mutate(category = factor(category, levels = c("Differences of being a girl adolescent with foreign-born parents vs immigrant background girl",
                                                "Differences of being an adolescents with foreign-born parents among boys",
                                                "Differences of being an adolescents with foreign-born parents among girls",
                                                "Differences of immigrant background among boys",
                                                "Differences of immigrant background among girls",
                                                "Differences of being girl among adolescents with foreign-born parents", 
                                                "Differences of being girl among immigrant background", 
                                                "Differences of being girl among non-immigrant background", 
                                                "Interaction effect for girl and adolescents with foreign-born parents", 
                                                "Interaction effect for girl and immigrant background")))
```

```{r}
h2_plot_con <- ggplot(plot_def_con, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.75) + 
  theme_minimal() +
  scale_y_discrete(labels = function(x) str_wrap(x, width = 51)) +  
  theme(panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0,size = 9,face = "bold",margin = margin(t = 20)),
    axis.text.y = element_text(size = 9)) 
plot(h2_plot_con)
```



### FOR COUNTRIES

#### WITHOUT controls

```{r}
w2_en_nocon <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec, data = data_wave2_en)
summary(w2_en_nocon)
```

```{r}
w2_ger_nocon <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec, data = data_wave2_ger)
summary(w2_ger_nocon)
```

```{r}
w2_neth_nocon <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec , data = data_wave2_neth)
summary(w2_neth_nocon)
```

```{r}
w2_sw_nocon <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec, data = data_wave2_sw)
summary(w2_sw_nocon)
```

#### WITH controls

```{r}
w2_model3_en <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_en)
summary(w2_model3_en)
```

```{r}
w2_model3_ger <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_ger)
summary(w2_model3_ger)
```

```{r}
w2_model3_neth <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_neth)
summary(w2_model3_neth)
```

```{r}
w2_model3_sw <- lm(poliint ~ female + immi_background_rec + female*immi_background_rec + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_sw)
summary(w2_model3_sw)
```


## Coefficients

### Without controls

```{r}
h2_nocon_comp_en <- glht(w2_en_nocon, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

```{r}
h2_nocon_comp_ger <- glht(w2_ger_nocon, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

```{r}
h2_nocon_comp_neth <- glht(w2_neth_nocon, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

```{r}
h2_nocon_comp_sw <- glht(w2_sw_nocon, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

### With controls

```{r}
h2_con_comp_en <- glht(w2_model3_en, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

```{r}
h2_con_comp_ger <- glht(w2_model3_ger, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

```{r}
h2_con_comp_neth <- glht(w2_model3_neth, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

```{r}
h2_con_comp_sw <- glht(w2_model3_sw, 
                    linfct = c("female + `female:immi_background_recImmigrant` = 0",
                               "female + `female:immi_background_recChild of immigrants` = 0",
                               "`immi_background_recImmigrant` + `female:immi_background_recImmigrant` = 0",
                               "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants` = 0"))
```

### Coefficient plot

### Without controls

### England

```{r}
coef_w2_nocon_en <- coef(w2_en_nocon)
confint_w2_nocon_en <- confint(w2_en_nocon)

table_w2_nocon_en <- data.frame(
  category = names(coef_w2_nocon_en),
  coefficient = coef_w2_nocon_en,
  IC_Lower = confint_w2_nocon_en[, 1],
  IC_Upper = confint_w2_nocon_en[, 2]) %>% 
  mutate(country = "England")
```

```{r}
coef_h2_nocon_comp_en <- summary(h2_nocon_comp_en)$test$coefficients
confint_h2_nocon_comp_en <- confint(h2_nocon_comp_en)$confint

table_h2_nocon_comp_en <- data.frame(
  category = names(coef_h2_nocon_comp_en),
  coefficient = coef_h2_nocon_comp_en,
  IC_Lower = confint_h2_nocon_comp_en[, 2],
  IC_Upper = confint_h2_nocon_comp_en[, 3]) %>% 
  mutate(country = "England")
```

### Germany

```{r}
coef_w2_nocon_ger <- coef(w2_ger_nocon)
confint_w2_nocon_ger <- confint(w2_ger_nocon)

table_w2_nocon_ger <- data.frame(
  category = names(coef_w2_nocon_ger),
  coefficient = coef_w2_nocon_ger,
  IC_Lower = confint_w2_nocon_ger[, 1],
  IC_Upper = confint_w2_nocon_ger[, 2]) %>% 
  mutate(country = "Germany")
```

```{r}
coef_h2_nocon_comp_ger <- summary(h2_nocon_comp_ger)$test$coefficients
confint_h2_nocon_comp_ger <- confint(h2_nocon_comp_ger)$confint

table_h2_nocon_comp_ger <- data.frame(
  category = names(coef_h2_nocon_comp_ger),
  coefficient = coef_h2_nocon_comp_ger,
  IC_Lower = confint_h2_nocon_comp_ger[, 2],
  IC_Upper = confint_h2_nocon_comp_ger[, 3]) %>% 
  mutate(country = "Germany")
```

### Netherlands

```{r}
coef_w2_nocon_neth <- coef(w2_neth_nocon)
confint_w2_nocon_neth <- confint(w2_neth_nocon)

table_w2_nocon_neth <- data.frame(
  category = names(coef_w2_nocon_neth),
  coefficient = coef_w2_nocon_neth,
  IC_Lower = confint_w2_nocon_neth[, 1],
  IC_Upper = confint_w2_nocon_neth[, 2]) %>% 
  mutate(country = "Netherlands")
```

```{r}
coef_h2_nocon_comp_neth <- summary(h2_nocon_comp_neth)$test$coefficients
confint_h2_nocon_comp_neth <- confint(h2_nocon_comp_neth)$confint

table_h2_nocon_comp_neth <- data.frame(
  category = names(coef_h2_nocon_comp_neth),
  coefficient = coef_h2_nocon_comp_neth,
  IC_Lower = confint_h2_nocon_comp_neth[, 2],
  IC_Upper = confint_h2_nocon_comp_neth[, 3]) %>% 
  mutate(country = "Netherlands")
```

### Sweden

```{r}
coef_w2_nocon_sw <- coef(w2_sw_nocon)
confint_w2_nocon_sw <- confint(w2_sw_nocon)

table_w2_nocon_sw <- data.frame(
  category = names(coef_w2_nocon_sw),
  coefficient = coef_w2_nocon_sw,
  IC_Lower = confint_w2_nocon_sw[, 1],
  IC_Upper = confint_w2_nocon_sw[, 2]) %>% 
  mutate(country = "Sweden")
```

```{r}
coef_h2_nocon_comp_sw <- summary(h2_nocon_comp_sw)$test$coefficients
confint_h2_nocon_comp_sw <- confint(h2_nocon_comp_sw)$confint

table_h2_nocon_comp_sw <- data.frame(
  category = names(coef_h2_nocon_comp_sw),
  coefficient = coef_h2_nocon_comp_sw,
  IC_Lower = confint_h2_nocon_comp_sw[, 2],
  IC_Upper = confint_h2_nocon_comp_sw[, 3]) %>% 
  mutate(country = "Sweden")
```

### With controls

### England

```{r}
coef_w2_model3_en <- coef(w2_model3_en)
confint_w2_model3_en <- confint(w2_model3_en)

table_w2_model3_en <- data.frame(
  category = names(coef_w2_model3_en),
  coefficient = coef_w2_model3_en,
  IC_Lower = confint_w2_model3_en[, 1],
  IC_Upper = confint_w2_model3_en[, 2]) %>% 
  mutate(country = "England")
```

```{r}
coef_h2_con_comp_en <- summary(h2_con_comp_en)$test$coefficients
confint_h2_con_comp_en <- confint(h2_con_comp_en)$confint

table_h2_con_comp_en <- data.frame(
  category = names(coef_h2_con_comp_en),
  coefficient = coef_h2_con_comp_en,
  IC_Lower = confint_h2_con_comp_en[, 2],
  IC_Upper = confint_h2_con_comp_en[, 3]) %>% 
  mutate(country = "England")
```

### Germany

```{r}
coef_w2_model3_ger <- coef(w2_model3_ger)
confint_w2_model3_ger <- confint(w2_model3_ger)

table_w2_model3_ger <- data.frame(
  category = names(coef_w2_model3_ger),
  coefficient = coef_w2_model3_ger,
  IC_Lower = confint_w2_model3_ger[, 1],
  IC_Upper = confint_w2_model3_ger[, 2]) %>% 
  mutate(country = "Germany")
```

```{r}
coef_h2_con_comp_ger <- summary(h2_con_comp_ger)$test$coefficients
confint_h2_con_comp_ger <- confint(h2_con_comp_ger)$confint

table_h2_con_comp_ger <- data.frame(
  category = names(coef_h2_con_comp_ger),
  coefficient = coef_h2_con_comp_ger,
  IC_Lower = confint_h2_con_comp_ger[, 2],
  IC_Upper = confint_h2_con_comp_ger[, 3]) %>% 
  mutate(country = "Germany")
```

### Netherlands

```{r}
coef_w2_model3_neth <- coef(w2_model3_neth)
confint_w2_model3_neth <- confint(w2_model3_neth)

table_w2_model3_neth <- data.frame(
  category = names(coef_w2_model3_neth),
  coefficient = coef_w2_model3_neth,
  IC_Lower = confint_w2_model3_neth[, 1],
  IC_Upper = confint_w2_model3_neth[, 2]) %>% 
  mutate(country = "Netherlands")
```

```{r}
coef_h2_con_comp_neth <- summary(h2_con_comp_neth)$test$coefficients
confint_h2_con_comp_neth <- confint(h2_con_comp_neth)$confint

table_h2_con_comp_neth <- data.frame(
  category = names(coef_h2_con_comp_neth),
  coefficient = coef_h2_con_comp_neth,
  IC_Lower = confint_h2_con_comp_neth[, 2],
  IC_Upper = confint_h2_con_comp_neth[, 3]) %>% 
  mutate(country = "Netherlands")
```

### Sweden

```{r}
coef_w2_model3_sw <- coef(w2_model3_sw)
confint_w2_model3_sw <- confint(w2_model3_sw)

table_w2_model3_sw <- data.frame(
  category = names(coef_w2_model3_sw),
  coefficient = coef_w2_model3_sw,
  IC_Lower = confint_w2_model3_sw[, 1],
  IC_Upper = confint_w2_model3_sw[, 2]) %>% 
  mutate(country = "Sweden")
```

```{r}
coef_h2_con_comp_sw <- summary(h2_con_comp_sw)$test$coefficients
confint_h2_con_comp_sw <- confint(h2_con_comp_sw)$confint

table_h2_con_comp_sw <- data.frame(
  category = names(coef_h2_con_comp_sw),
  coefficient = coef_h2_con_comp_sw,
  IC_Lower = confint_h2_con_comp_sw[, 2],
  IC_Upper = confint_h2_con_comp_sw[, 3]) %>% 
  mutate(country = "Sweden")
```

## Alternative model 

#### WITHOUT controls

```{r}
w2_en_nocon_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_en)
```

```{r}
w2_ger_nocon_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_ger)
```

```{r}
w2_neth_nocon_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_neth)
```

```{r}
w2_sw_nocon_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_sw)
```

### WITH controls

```{r}
w2_model3_en_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_en)
```

```{r}
w2_model3_ger_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_ger)
```

```{r}
w2_model3_neth_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_neth)
```

```{r}
w2_model3_sw_alt <- lm(poliint ~  combi_fem_migr + country_origin + nationality + age + book_home + talk_parents_pol + associationism + religious_part + mixed_friend, data = data_wave2_sw)
```

## Coefficients

### WITHOUT controls

## England

```{r}
w2_en_nocon_comp_alt <- glht(w2_en_nocon_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_en_nocon_comp_alt_res <- summary(w2_en_nocon_comp_alt)
```

```{r}
coef_w2_en_nocon_comp_alt <- coef(w2_en_nocon_comp_alt_res)
confint_w2_en_nocon_comp_alt <- confint(w2_en_nocon_comp_alt)$confint

table_w2_en_nocon_comp_alt <- data.frame(
  category = names(coef_w2_en_nocon_comp_alt),
  coefficient = coef_w2_en_nocon_comp_alt,
  IC_Lower = confint_w2_en_nocon_comp_alt[, 2],
  IC_Upper = confint_w2_en_nocon_comp_alt[, 3])%>% 
  mutate(country = "England")
```

## Germany

```{r}
w2_ger_nocon_comp_alt <- glht(w2_ger_nocon_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_ger_nocon_comp_alt_res <- summary(w2_ger_nocon_comp_alt)
```

```{r}
coef_w2_ger_nocon_comp_alt <- coef(w2_ger_nocon_comp_alt_res)
confint_w2_ger_nocon_comp_alt <- confint(w2_ger_nocon_comp_alt)$confint

table_w2_ger_nocon_comp_alt <- data.frame(
  category = names(coef_w2_ger_nocon_comp_alt),
  coefficient = coef_w2_ger_nocon_comp_alt,
  IC_Lower = confint_w2_ger_nocon_comp_alt[, 2],
  IC_Upper = confint_w2_ger_nocon_comp_alt[, 3])%>% 
  mutate(country = "Germany")
```

## Netherlands

```{r}
w2_neth_nocon_comp_alt <- glht(w2_neth_nocon_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_neth_nocon_comp_alt_res <- summary(w2_neth_nocon_comp_alt)
```

```{r}
coef_w2_neth_nocon_comp_alt <- coef(w2_neth_nocon_comp_alt_res)
confint_w2_neth_nocon_comp_alt <- confint(w2_neth_nocon_comp_alt)$confint

table_w2_neth_nocon_comp_alt <- data.frame(
  category = names(coef_w2_neth_nocon_comp_alt),
  coefficient = coef_w2_neth_nocon_comp_alt,
  IC_Lower = confint_w2_neth_nocon_comp_alt[, 2],
  IC_Upper = confint_w2_neth_nocon_comp_alt[, 3]) %>% 
  mutate(country = "Netherlands")
```

## Sweden

```{r}
w2_sw_nocon_comp_alt <- glht(w2_sw_nocon_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_sw_nocon_comp_alt_res <- summary(w2_sw_nocon_comp_alt) 
```

```{r}
coef_w2_sw_nocon_comp_alt <- coef(w2_sw_nocon_comp_alt_res)
confint_w2_sw_nocon_comp_alt <- confint(w2_sw_nocon_comp_alt)$confint

table_w2_sw_nocon_comp_alt <- data.frame(
  category = names(coef_w2_sw_nocon_comp_alt),
  coefficient = coef_w2_sw_nocon_comp_alt,
  IC_Lower = confint_w2_sw_nocon_comp_alt[, 2],
  IC_Upper = confint_w2_sw_nocon_comp_alt[, 3]) %>% 
  mutate(country = "Sweden")
```

### WITH controls

## England

```{r}
w2_en_con_comp_alt <- glht(w2_model3_en_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_en_con_comp_alt_res <- summary(w2_en_con_comp_alt)
```

```{r}
coef_w2_en_con_comp_alt <- coef(w2_en_con_comp_alt_res)
confint_w2_en_con_comp_alt <- confint(w2_en_con_comp_alt)$confint

table_w2_en_con_comp_alt <- data.frame(
  category = names(coef_w2_en_con_comp_alt),
  coefficient = coef_w2_en_con_comp_alt,
  IC_Lower = confint_w2_en_con_comp_alt[, 2],
  IC_Upper = confint_w2_en_con_comp_alt[, 3]) %>% 
  mutate(country = "England")
```

## Germany

```{r}
w2_ger_con_comp_alt <- glht(w2_model3_ger_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_ger_con_comp_alt_res <- summary(w2_ger_con_comp_alt)
```

```{r}
coef_w2_ger_con_comp_alt <- coef(w2_ger_con_comp_alt_res)
confint_w2_ger_con_comp_alt <- confint(w2_ger_con_comp_alt)$confint

table_w2_ger_con_comp_alt <- data.frame(
  category = names(coef_w2_ger_con_comp_alt),
  coefficient = coef_w2_ger_con_comp_alt,
  IC_Lower = confint_w2_ger_con_comp_alt[, 2],
  IC_Upper = confint_w2_ger_con_comp_alt[, 3]) %>% 
  mutate(country = "Germany")
```

## Netherlands

```{r}
w2_neth_con_comp_alt <- glht(w2_model3_neth_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_neth_con_comp_alt_res <- summary(w2_neth_con_comp_alt)
```

```{r}
coef_w2_neth_con_comp_alt <- coef(w2_neth_con_comp_alt_res)
confint_w2_neth_con_comp_alt <- confint(w2_neth_con_comp_alt)$confint

table_w2_neth_con_comp_alt <- data.frame(
  category = names(coef_w2_neth_con_comp_alt),
  coefficient = coef_w2_neth_con_comp_alt,
  IC_Lower = confint_w2_neth_con_comp_alt[, 2],
  IC_Upper = confint_w2_neth_con_comp_alt[, 3]) %>% 
  mutate(country = "Netherlands")
```

## Sweden

```{r}
w2_sw_con_comp_alt <- glht(w2_model3_sw_alt, 
                   linfct = mcp(combi_fem_migr = "Tukey"))
w2_sw_con_comp_alt_res <- summary(w2_sw_con_comp_alt)
```

```{r}
coef_w2_sw_con_comp_alt <- coef(w2_sw_con_comp_alt_res)
confint_w2_sw_con_comp_alt <- confint(w2_sw_con_comp_alt)$confint

table_w2_sw_con_comp_alt <- data.frame(
  category = names(coef_w2_sw_con_comp_alt),
  coefficient = coef_w2_sw_con_comp_alt,
  IC_Lower = confint_w2_sw_con_comp_alt[, 2],
  IC_Upper = confint_w2_sw_con_comp_alt[, 3]) %>% 
  mutate(country = "Sweden")
```


## Plot without controls

```{r}
plot_h2_nocon_coun <- table_w2_nocon_en %>% 
  rbind(table_h2_nocon_comp_en) %>% 
  rbind(table_w2_en_nocon_comp_alt) %>% 
  rbind(table_w2_nocon_ger) %>% 
  rbind(table_h2_nocon_comp_ger) %>% 
  rbind(table_w2_ger_nocon_comp_alt) %>%
  rbind(table_w2_nocon_neth) %>% 
  rbind(table_h2_nocon_comp_neth) %>% 
  rbind(table_w2_neth_nocon_comp_alt) %>%
  rbind(table_w2_nocon_sw) %>% 
  rbind(table_h2_nocon_comp_sw) %>% 
  rbind(table_w2_sw_nocon_comp_alt)  %>%
  filter(category %in% c("female", "immi_background_recImmigrant", "immi_background_recChild of immigrants", "female:immi_background_recImmigrant", "female:immi_background_recChild of immigrants", "female + `female:immi_background_recImmigrant`", "female + `female:immi_background_recChild of immigrants`", "immi_background_recImmigrant + `female:immi_background_recImmigrant`", "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`", "Child_of_Immigrants_Female - Immigrant_Female")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_recImmigrant" ~ "Interaction effect for girl and immigrant background",
    category == "female:immi_background_recChild of immigrants" ~ "Interaction effect for girl and adolescents with foreign-born parents",
    category == "female" ~ "Differences of being girl among non-immigrant background",
    category == "immi_background_recImmigrant" ~ "Differences of immigrant background among boys",
    category == "immi_background_recChild of immigrants" ~ "Differences of being an adolescents with foreign-born parents among boys",
    category == "female + `female:immi_background_recImmigrant`" ~ "Differences of being girl among immigrant background",
    category == "female + `female:immi_background_recChild of immigrants`" ~ "Differences of being girl among adolescents with foreign-born parents", 
    category == "immi_background_recImmigrant + `female:immi_background_recImmigrant`" ~ "Differences of immigrant background among girls",
    category == "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`" ~ "Differences of being an adolescents with foreign-born parents among girls",
      category == "Child_of_Immigrants_Female - Immigrant_Female" ~ "Differences of being a girl adolescent with foreign-born parents vs immigrant background girl")) %>% 
  mutate(category = factor(category, levels = c("Differences of being a girl adolescent with foreign-born parents vs immigrant background girl",
                                                "Differences of being an adolescents with foreign-born parents among boys",
                                                "Differences of being an adolescents with foreign-born parents among girls",
                                                "Differences of immigrant background among boys",
                                                "Differences of immigrant background among girls",
                                                "Differences of being girl among adolescents with foreign-born parents", 
                                                "Differences of being girl among immigrant background", 
                                                "Differences of being girl among non-immigrant background", 
                                                "Interaction effect for girl and adolescents with foreign-born parents", 
                                                "Interaction effect for girl and immigrant background")))
```

```{r, fig.width=10, fig.height=7}
h2_nocon_count <- ggplot(plot_h2_nocon_coun, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.5) + 
  facet_wrap(~ country, ncol = 2) +
  theme_minimal() +
  scale_y_discrete(labels = function(x) str_wrap(x, width = 75)) +  
  theme(
    panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0, size = 9, face = "bold", margin = margin(t = 20)),
    axis.text.y = element_text(size = 9, lineheight = 1))  

plot(h2_nocon_count)
```


## Plot without controls

```{r}
plot_h2_con_coun <- table_w2_model3_en %>% 
  rbind(table_h2_con_comp_en) %>% 
  rbind(table_w2_en_con_comp_alt) %>% 
  rbind(table_w2_model3_ger) %>% 
  rbind(table_h2_con_comp_ger) %>% 
  rbind(table_w2_ger_con_comp_alt) %>%
  rbind(table_w2_model3_neth) %>% 
  rbind(table_h2_con_comp_neth) %>% 
  rbind(table_w2_neth_con_comp_alt) %>%
  rbind(table_w2_model3_sw) %>% 
  rbind(table_h2_con_comp_sw) %>% 
  rbind(table_w2_sw_con_comp_alt)  %>%
  filter(category %in% c("female", "immi_background_recImmigrant", "immi_background_recChild of immigrants", "female:immi_background_recImmigrant", "female:immi_background_recChild of immigrants", "female + `female:immi_background_recImmigrant`", "female + `female:immi_background_recChild of immigrants`", "immi_background_recImmigrant + `female:immi_background_recImmigrant`", "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`", "Child_of_Immigrants_Female - Immigrant_Female")) %>% 
    mutate(category = case_when(
    category == "female:immi_background_recImmigrant" ~ "Interaction effect for girl and immigrant background",
    category == "female:immi_background_recChild of immigrants" ~ "Interaction effect for girl and adolescents with foreign-born parents",
    category == "female" ~ "Differences of being girl among non-immigrant background",
    category == "immi_background_recImmigrant" ~ "Differences of immigrant background among boys",
    category == "immi_background_recChild of immigrants" ~ "Differences of being an adolescents with foreign-born parents among boys",
    category == "female + `female:immi_background_recImmigrant`" ~ "Differences of being girl among immigrant background",
    category == "female + `female:immi_background_recChild of immigrants`" ~ "Differences of being girl among adolescents with foreign-born parents", 
    category == "immi_background_recImmigrant + `female:immi_background_recImmigrant`" ~ "Differences of immigrant background among girls",
    category == "`immi_background_recChild of immigrants` + `female:immi_background_recChild of immigrants`" ~ "Differences of being an adolescents with foreign-born parents among girls",
      category == "Child_of_Immigrants_Female - Immigrant_Female" ~ "Differences of being a girl adolescent with foreign-born parents vs immigrant background girl")) %>% 
  mutate(category = factor(category, levels = c("Differences of being a girl adolescent with foreign-born parents vs immigrant background girl",
                                                "Differences of being an adolescents with foreign-born parents among boys",
                                                "Differences of being an adolescents with foreign-born parents among girls",
                                                "Differences of immigrant background among boys",
                                                "Differences of immigrant background among girls",
                                                "Differences of being girl among adolescents with foreign-born parents", 
                                                "Differences of being girl among immigrant background", 
                                                "Differences of being girl among non-immigrant background", 
                                                "Interaction effect for girl and adolescents with foreign-born parents", 
                                                "Interaction effect for girl and immigrant background")))
```

```{r, fig.width=10, fig.height=7}
h2_con_count <- ggplot(plot_h2_con_coun, aes(x = coefficient, y = category)) +
  geom_point() +
  geom_errorbarh(aes(xmin = IC_Lower, xmax = IC_Upper), height = 0.2) + 
  geom_vline(xintercept = 0, linetype = "dashed") +
  geom_text(aes(label = round(coefficient, 2)), hjust = 0.5, vjust = -0.75, size = 2.5) + 
  facet_wrap(~ country, ncol = 2) +
  theme_minimal() +
  scale_y_discrete(labels = function(x) str_wrap(x, width = 75)) +  
  theme(
    panel.background = element_rect(fill = "white"), 
    panel.grid.major = element_blank(),  
    panel.grid.minor = element_blank(),  
    axis.title.x = element_blank(),     
    axis.title.y = element_blank(), 
    plot.caption = element_text(hjust = -8, vjust = 0, size = 9, face = "bold", margin = margin(t = 20)),
    axis.text.y = element_text(size = 9, lineheight = 1)) 

plot(h2_con_count)
```


# T-tests


```{r}
t_test_fem_gene <- t.test(poliint ~ female, data = data_wave2)
t_test_fem_gene
```

```{r}
t_test_fem_ger <- t.test(poliint ~ female, data = data_wave2_ger)
t_test_fem_ger
```

```{r}
t_test_fem_sw <- t.test(poliint ~ female, data = data_wave2_sw)
t_test_fem_sw
```

```{r}
t_test_fem_neth <- t.test(poliint ~ female, data = data_wave2_neth)
t_test_fem_neth
```

```{r}
t_test_fem_en <- t.test(poliint ~ female, data = data_wave2_en)
t_test_fem_en
```

# Immigrant background ANOVA test

```{r}
anova_immi <- aov(poliint ~ immi_background_rec, data = data_wave2)
summary(anova_immi)
TukeyHSD(anova_immi)
```

```{r}
anova_immi_sw <- aov(poliint ~ immi_background_rec, data = data_wave2_sw)
summary(anova_immi_sw)
```

```{r}
anova_immi_en <- aov(poliint ~ immi_background_rec, data = data_wave2_en)
summary(anova_immi_en)
```

```{r}
anova_immi_neth <- aov(poliint ~ immi_background_rec, data = data_wave2_neth)
summary(anova_immi_neth)
```

```{r}
anova_immi_ger <- aov(poliint ~ immi_background_rec, data = data_wave2_ger)
summary(anova_immi_ger)
```


# Additional robustness check: 

## Order logit model; hypothesis 1

```{r}
data_model_h1$poliint <- factor(data_model_h1$poliint, ordered = TRUE)

h1_model3_ordinal <- polr(poliint ~ female + immi_background_dic + female * immi_background_dic + country_origin + nationality + age + book_home +  talk_parents_pol + associationism + religious_part + mixed_friend,  data = data_model_h1, Hess = TRUE)
summary(h1_model3_ordinal)
```

## Order logit model; hypothesis 2

```{r}
data_model_h2$poliint <- factor(data_model_h2$poliint, ordered = TRUE)

h2_model3_ordinal <- polr(poliint ~ female + immi_background_rec + female * immi_background_rec + country_origin + nationality + age + book_home +  talk_parents_pol + associationism + religious_part + mixed_friend,  data = data_model_h2, Hess = TRUE)
summary(h2_model3_ordinal)
```



#### Stargazer models

```{r}
hypothesis1 <- stargazer(h1_model1, h1_model2, h1_model3, type = "html", align = TRUE, out = NULL,
                    covariate.labels = c("Female", "Immigrant (ref=Native)", "Europe and North America (ref=Survey country)", "Asia (ref=Survey country)", "Latin America and Caribbean (ref=Survey country)", "Africa and Middle East (ref=Survey country)", "Survey country and other nationality (ref=Only survey country nationality)", "Only other nationality (ref=Only survey country nationality)", "Age", "Books at home", "Parents political talk", "Associationism", "Religious participation", "Mixed friendship", "Female*Immigrant"),
                   dep.var.labels = "Political interest")
writeLines(hypothesis1, "hypothesis1.html")
```

```{r}
hypothesis1_countries <- stargazer(h1_model3_en, h1_model3_ger, h1_model3_neth, h1_model3_sw, type = "html", align = TRUE, out = NULL,
                    covariate.labels = c("Female", "Immigrant (ref=Native)", "Europe and North America (ref=Survey country)", "Asia (ref=Survey country)", "Latin America and Caribbean (ref=Survey country)", "Africa and Middle East (ref=Survey country)", "Survey country and other nationality (ref=Only survey country nationality)", "Only other nationality (ref=Only survey country nationality)", "Age", "Books at home", "Parents political talk", "Associationism", "Religious participation", "Mixed friendship", "Female*Immigrant"),
                   dep.var.labels = "Political interest",
                   column.labels = c("England", "Germany", "Netherlands", "Sweden"))
writeLines(hypothesis1_countries, "hypothesis1_countries.html")
```

```{r}
hypothesis1_countries_nocon <- stargazer(h1_en_nocon, h1_ger_nocon, h1_neth_nocon, h1_sw_nocon, type = "html", align = TRUE, out = NULL,
                  covariate.labels = c("Female", "Immigrant (ref=Native)", "Female*Immigrant"),
                   dep.var.labels = "Political interest",
                   column.labels = c("England", "Germany", "Netherlands", "Sweden"))
writeLines(hypothesis1_countries_nocon, "hypothesis1_countries_nocon.html")
```

```{r}
hypothesis1_ordinal <- stargazer(h1_model3_ordinal, type = "html", align = TRUE, out = NULL,
                    covariate.labels = c("Female", "Immigrant (ref=Native)", "Europe and North America (ref=Survey country)", "Asia (ref=Survey country)", "Latin America and Caribbean (ref=Survey country)", "Africa and Middle East (ref=Survey country)", "Survey country and other nationality (ref=Only survey country nationality)", "Only other nationality (ref=Only survey country nationality)", "Age", "Books at home", "Parents political talk", "Associationism", "Religious participation", "Mixed friendship", "Female*Immigrant"),                   dep.var.labels = "Political interest")
writeLines(hypothesis1_ordinal, "hypothesis1_ordinal.html")
```


```{r}
hypothesis2 <- stargazer(w2_model1, w2_model2, w2_model3, type = "html", align = TRUE, out = NULL,
                    covariate.labels = c("Female", "Immigrant (ref=Other/Native)", "Child of immigrants (ref=Other/Native)", "Europe and North America (ref=Survey country)", "Asia (ref=Survey country)", "Latin America and Caribbean (ref=Survey country)", "Africa and Middle East (ref=Survey country)", "Survey country and other nationality (ref=Only survey country nationality)", "Only other nationality (ref=Only survey country nationality)", "Age", "Books at home", "Parents political talk", "Associationism", "Religious participation", "Mixed friendship", "Female*Immigrant", "Female*Child of immigrants"),
                   dep.var.labels = "Political interest")
writeLines(hypothesis2, "hypothesis2.html")
```

```{r}
hypothesis2_countries <- stargazer(w2_model3_en, w2_model3_ger, w2_model3_neth, w2_model3_sw, type = "html", align = TRUE, out = NULL,
                    covariate.labels = c("Female", "Immigrant (ref=Other/Native)", "Child of immigrants (ref=Other/Native)", "Europe and North America (ref=Survey country)", "Asia (ref=Survey country)", "Latin America and Caribbean (ref=Survey country)", "Africa and Middle East (ref=Survey country)", "Survey country and other nationality (ref=Only survey country nationality)", "Only other nationality (ref=Only survey country nationality)", "Age", "Books at home", "Parents political talk", "Associationism", "Religious participation", "Mixed friendship", "Female*Immigrant", "Female*Child of immigrants"),
                   dep.var.labels = "Political interest",
                   column.labels = c("England", "Germany", "Netherlands", "Sweden"))
writeLines(hypothesis2_countries, "hypothesis2_countries.html")
```

```{r}
hypothesis2_countries_nocon <- stargazer(w2_en_nocon, w2_ger_nocon, w2_neth_nocon, w2_sw_nocon, type = "html", align = TRUE, out = NULL,
                                         covariate.labels = c("Female", "Immigrant (ref=Other/Native)", "Child of immigrants (ref=Other/Native)", "Female*Immigrant", "Female*Child of immigrants"),
                   dep.var.labels = "Political interest",
                   column.labels = c("England", "Germany", "Netherlands", "Sweden"))
writeLines(hypothesis2_countries_nocon, "hypothesis2_countries_nocon.html")
```


```{r}
hypothesis2_ordinal <- stargazer(h2_model3_ordinal, type = "html", align = TRUE, out = NULL,
                    covariate.labels = c("Female", "Immigrant (ref=Other/Native)", "Child of immigrants (ref=Other/Native)", "Europe and North America (ref=Survey country)", "Asia (ref=Survey country)", "Latin America and Caribbean (ref=Survey country)", "Africa and Middle East (ref=Survey country)", "Survey country and other nationality (ref=Only survey country nationality)", "Only other nationality (ref=Only survey country nationality)", "Age", "Books at home", "Parents political talk", "Associationism", "Religious participation", "Mixed friendship", "Female*Immigrant", "Female*Child of immigrants"),
                   dep.var.labels = "Political interest")
writeLines(hypothesis2_ordinal, "hypothesis2_ordinal.html")
```

